#!/usr/bin/python

# Change to SimpleJson
import simplejson as json
import urllib2

mac = open("/etc/macaddr.txt").read()

# First, download the configuration
configraw = urllib2.urlopen("http://service.config.transitappliance.com/_je/publicConfig?cond=id.eq.MAC:%s" %  mac)

config = json.load(configraw)

if len(config) > 0:
    print config[0]['url']
else:
    noconfig = open('/tmp/noconfig.html', 'w')
    noconfig.write("""
<html>
<head>
  <title>No configuration found</title>
</head>
<body>
No configuration was found for this device. If you have a keyboard and a mouse
connected, you may
<a href="http://service.config.transitappliance.com">configure your appliance
now</a>. Otherwise, write down the code <b>%s</b> and go to
<b>http://service.config.transitappliance.com</b> on another computer. Either
way, you will need a Google account to complete the configuration.
</body>
</html>
""" % mac)
    print "file:///tmp/noconfig.html"
            

